#include <iostream>

#include <vector>

#include <string>

#include <fstream>

using namespace std;

void main()
{
	char fName[] = "input.txt";
	string str;

	vector<vector<string>> doanVan;

	ifstream fin(fName, ios::in);

	vector<string> se(1);

	while (fin)
	{
		bool flag_push  = false;
		if (fin >> str == false)
			break;
		switch (char c = str[str.length()-1])
		{
		case ',':
			se[0].push_back(',');
			str.erase(str.end()-1);
			break;
		case '.':
		case '!':
		case '?':
			str.erase(str.end()-1);
			se[0].push_back(c);
			flag_push = true;
			break;
		default:
			se[0].push_back(' ');
		}

		se.push_back(str);

		if (flag_push)
		{	
			doanVan.push_back(se);
			se.resize(1);
			se[0].clear();
		}
	}

	fin.close();
	doanVan.size();
	for (int i = 0; i < doanVan.size(); i++)

	{
		for (int j = 1; j < doanVan[i].size(); j++)
		{
			cout << doanVan[i][j];
			if (doanVan[i][0][j-1] != ' ')
				cout << doanVan[i][0][j-1];
			cout << " ";
		}
	}
}